Extract adjacent distances from distance matrix