LaTo, that ain't work at all. Functions of Avisynth's conditional environment can only be used - you guess it - in Avisynth's conditional environment.
Besides, a simple thresholded difference to the previous frame isn't smart enough. That diff might be rather low e.g. in dark scenes, and might be rather high e.g. in pannings, explosion scenes and such, yielding to frame freezes in places where you
definetly don't want them.
This method has been used already yeeaars ago. The result is it works in some places and in some not. High thresholds will miss many scenechanges, low thresholds give many false detections. In between, you get a mix of both.
I'd rather try try examining the 2nd derivative ... example: look at the diff-to-previous over three frames. If the middle one is reasonably bigger then the surrounding two ones, then a scenechange is likely. To be sure, take a 5-frame window, and evaluate the proportion of the diff-of-differences at the start & the end of that window to the one in the middle.