Fix wrong swapping in SortByDist (thx koebi)