How DTW (Dynamic Time Warping) algorithm works