An expression of the form SEQ[position() ne $X] is rewritten to use the remove() function - essentially remove(SEQ, if (isWholeNumber($X)) then $X else 0)
Unfortunately this rewrite fails in the case where $X is not an integer, on the grounds that remove() requires the second argument to be an integer. The error message refers to a type error in the second argument of remove(), without giving the location of the error.
A patch is being placed in Subversion. As a workaround, declare the types of your variables to be integers if they actually are integers!