def calculate_relative_speed(dists, dts):
    """
    Calculates the relative speed of the obstacle to the rover using previously
    recorded obstacle distances and time differences.

    :param collections.deque[int] dists: The previously measured obstacle
    distances. (cm)
    :param collections.deque[float] dts: The previously measured time
    differences. (s)
    :return: The relative speed of the obstacle. (cm/s)
    """
    old_dist = sum(list(dists)[0:len(dists) / 2]) / (len(dists) / 2)
    new_dist = sum(list(dists)[len(dists) / 2:]) / (len(dists) / 2)

    avg_dt = sum(list(dts)) / len(dts)

    rel_speed = (new_dist - old_dist) / ((len(dists) / 2.0 - 1) * avg_dt)

    return rel_speed