The ```try```/```except``` here seems a little strange. I think it would be clearer to do something like this:

    for i in range(len(filtered_idx) - 1):

I think it is a little dangerous to catch ```IndexError``` here since you are indexing into two different data structures, each of which has the possibility of raising an ```IndexError```.