def minimum_distance(mp, ip, dp, i):
    """

        Compares each element from the distance profile with the corresponding element from the matrix profile.

        Parameters
        ----------
            mp: numpy.array
                Matrix profile.
            ip: numpy.array
                Index profile.
            dp: numpy.array
                Distance profile.
            i: int
                Index of the element to be compared from the matrix profile.

        Output
        ------
            mp: numpy.array
                Array with the distance between every subsequence from ts1 to the nearest subsequence with same length from ts2.
            ip: numpy.array
                Array with the index of the ts1's nearest neighbor in ts2.

    """

    for k in range(0, dp.size):
        if dp[k] < mp[i]:
            mp[i] = dp[k]
            ip[i] = k

    return mp, ip