BUG: spatial.distance: fix unchecked malloc
MAINT: spatial.distance: further refactoring

* static on all functions in distance_impl.h
* commented out unused compute_mean_vector
* replaced &&, || with &, | in tight loops
* reindented code according to NumPy conventions
* removed some useless variables