[SPARK-2517] Removed some compiler type erasure warnings.

Also took the chance to rename some variables to avoid unintentional shadowing.