I had a quick look at this, and what it seems to be doing is encountering a rounding issue when you are trying to set keyframes before and after the current time. When you have a mid-point that is not an even number, such as 17.5 for the previous keyframe and 32.5 for the next keyframe, and you pass those float values to setKeyframe(), it is going to round them both up to the next whole number. that is going to result in the left side being a closer distance from your current time and the right side being farther away.
If your goal is to make them an even distance from the current time, then a possible solution is to always round the left side up, and always round the right side down.
This example is wrapping the prev and next keyframe locations in math.ceil() and math.floor(), respectively:
Justin