Index: src/bp-core/classes/class-bp-user-query.php
===================================================================
--- src/bp-core/classes/class-bp-user-query.php
+++ src/bp-core/classes/class-bp-user-query.php
@@ -595,13 +595,17 @@
 		}
 
 		// Match up to the user ids from the main query
-		foreach ( $this->user_ids as $uid ) {
+		foreach ( $this->user_ids as $key => $uid ) {
 			if ( isset( $r[ $uid ] ) ) {
 				$this->results[ $uid ] = $r[ $uid ];
 
 				// The BP template functions expect an 'id'
 				// (as opposed to 'ID') property
 				$this->results[ $uid ]->id = $uid;
+
+			// remove user ID from original user_ids property
+			} else {
+				unset( $this->user_ids[ $key ] );
 			}
 		}
 	}
Index: src/bp-friends/bp-friends-filters.php
===================================================================
--- src/bp-friends/bp-friends-filters.php
+++ src/bp-friends/bp-friends-filters.php
@@ -60,7 +60,10 @@
 		if ( bp_loggedin_user_id() == $nf ) {
 			continue;
 		}
-		$user_query->results[ $nf ]->friendship_status = 'not_friends';
+
+		if ( isset( $user_query->results[ $nf ] ) ) {
+			$user_query->results[ $nf ]->friendship_status = 'not_friends';
+		}
 	}
 
 }
Index: tests/phpunit/testcases/core/class-bp-user-query.php
===================================================================
--- tests/phpunit/testcases/core/class-bp-user-query.php
+++ tests/phpunit/testcases/core/class-bp-user-query.php
@@ -66,6 +66,32 @@
 		$this->assertEquals( $friend_ids, array() );
 	}
 
+	/**
+	 * @group user_ids
+	 */
+	public function test_bp_user_query_user_ids_with_invalid_user_id() {
+		$now = time();
+		$u1 = $this->factory->user->create();
+		$u2 = $this->factory->user->create();
+
+		// invalid user ID
+		$u3 = $u2 + 1;
+
+		$old_user = get_current_user_id();
+		$this->set_current_user( $u1 );
+
+		// pass 'user_ids' to user query to trigger this bug
+		$q = new BP_User_Query( array(
+			'user_ids' => array( $u2, $u3 )
+		) );
+
+		// $q->user_ids property should now not contain invalid user IDs
+		$this->assertNotContains( $u3, $q->user_ids );
+
+		// clean up
+		$this->set_current_user( $old_user );
+	}
+
 	public function test_bp_user_query_sort_by_popular() {
 		$u1 = $this->factory->user->create();
 		$u2 = $this->factory->user->create();
