CRM-13133 - also fix some notices and  pass-by reference warnings

----------------------------------------
* CRM-13133: Advanced Search is incorrectly including contacts removed from a group
  http://issues.civicrm.org/jira/browse/CRM-13133