better implementation of kdtree DualTreeWalker