Just pull the wrapping of the scanner out of the if to do the TODO below, as then the getTopNScanner will work when there are array index references, like this:

    innerScanner = getWrappedScanner(c, innerScanner, arrayKVRefs, arrayFuncRefs);
    if (iterator == null) {
        return innerScanner;
    }