kdtree implemented in cython for speed