knn_dist function

calculate k nearest neighbours from a distance matrix