CP-Guard: Malicious Agent Detection and Defense in Collaborative Bird's Eye View Perception