Not clear which array it is you wish sorted but mayhaps can accomplish directly -- altho the auxiliary array and distances may be needed to have been computed, not knowing exactly the problem trying to solve.
But, given the index vector you've built, simply
if we presume this mystery array is 'A' will rearrange rows in that order.
As Bruno points out, I mixed metaphors/switched horses midstream...
to sort the columns instead, of course.