Closest centroid kdtree function