implemented dtw matrix