fixed median function in kdtree.cpp so that correct median is returned