Gamma difference isn't the issue, You_Too. The 2004 SE (B reference) frame is massively clipped which is causing problems when redistributing the 97 SE RGB luma.
I've equalised the RGB luma in your A & B reference frames to illustrate the extent of the clipping in the 2004 SE. The only way this script might work with the 2004 SE/Blu-ray is if it's modified to affect hue only.