Kdtree knn implementation