analog pin smoothing function gives strange results

which works fine. But when I put it in a greater project (the version above is for testing only), I get the following strange behavior. The first potentiometer is being read fine, but all the rest have their resolution reduced according to the number of samples I take (the SMOOTH macro). If I take 2 samples, the maximum value the pots give is 4095. If I take 3 samples, it's 2730. If I take 4, it's 2047 etc. If I take 1 sample it's 8191, as it should (13-bit resolution). I have to mention that in the greater project I'm using multiplexers. A main multiplexer is controlling other multiplexers where the pots are wired.

I've read in more than one thread, that after switching to another analog input the first read should be discarded. In other words, read twice.

Or perhaps a solution could be found here: http://forum.arduino.cc/index.php?topic=18339.0

Been away from this thread for some days due to busy schedule.

@AWOL your implementation seems to work! I applied this to the already existing code of the "big" project and all pots had their 13-bit resolution untouched! Thanks a lot!