<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def good_sequences_to_track(flow, motion_threshold=1.0):
 """Get list of good frames to do tracking in. Looking at the optical flow, this function chooses a span of frames that fulfill certain criteria. These include * not being too short or too long * not too low or too high mean flow magnitude * a low max value (avoids motion blur) Currently, the cost function for a sequence is hard coded. Sorry about that. Parameters flow : ndarray The optical flow magnitude motion_threshold : float The maximum amount of motion to consider for sequence endpoints. Returns sequences : list Sorted list of (a, b, score) elements (highest scpre first) of sequences where a sequence is frames with frame indices in the span [a, b]. """

    endpoints = []
    in_low = False
    for i, val in enumerate(flow):
        if val < motion_threshold:
            if not in_low:
                endpoints.append(i)
                in_low = True
        else:
            if in_low:
                endpoints.append(i-1) # Previous was last in a low spot
            in_low = False
    
    def mean_score_func(m):
        mu = 15
        sigma = 8
        top_val = normpdf(mu, mu, sigma)
        return normpdf(m, mu, sigma) / top_val
    
    def max_score_func(m):
        mu = 40
        sigma = 8
        if m <= mu:
            return 1.
        else:
            top_val = normpdf(mu, mu, sigma)
            return normpdf(m, mu, sigma) / top_val
    
    def length_score_func(l):
        mu = 30
        sigma = 10
        top_val = normpdf(mu, mu, sigma)
        return normpdf(l, mu, sigma) / top_val
    
    min_length = 5 # frames
    sequences = []
    for k, i in enumerate(endpoints[:-1]):
        for j in endpoints[k+1:]:
            length = j - i
            if length < min_length:
                continue
            seq = flow[i:j+1]
            m_score = mean_score_func(np.mean(seq))
            mx_score = max_score_func(np.max(seq))
            l_score = length_score_func(length)
            logger.debug("%d, %d scores: (mean=%.5f, max=%.5f, length=%.5f)" % (i,j,m_score, mx_score, l_score))
            if min(m_score, mx_score, l_score) < 0.2:
                continue
            
            score = m_score + mx_score + l_score 
            sequences.append((i, j, score))

    return sorted(sequences, key=lambda x: x[2], reverse=True)